#include "isd1820.h"

ISD1820::ISD1820(uint8_t ftPin, uint8_t playLPin, uint8_t playEPin, uint8_t recPin)
    : ftPin(ftPin), playLPin(playLPin), playEPin(playEPin), recPin(recPin) {}

void ISD1820::begin() {
    pinMode(ftPin, OUTPUT);
    pinMode(playLPin, OUTPUT);
    pinMode(playEPin, OUTPUT);
    pinMode(recPin, OUTPUT);

    digitalWrite(ftPin, LOW);  // Set to play mode
    digitalWrite(playLPin, LOW);
    digitalWrite(playEPin, LOW);
    digitalWrite(recPin, LOW);
}

void ISD1820::play(uint8_t startAddr, uint8_t endAddr) {
    digitalWrite(ftPin, LOW);  // Play mode
    digitalWrite(playLPin, startAddr);
    digitalWrite(playEPin, endAddr);
    digitalWrite(recPin, LOW);

    delay(100);  // Wait for the playback to start

    digitalWrite(playLPin, LOW);
    digitalWrite(playEPin, LOW);
}

void ISD1820::record(uint8_t startAddr) {
    digitalWrite(ftPin, HIGH);  // Record mode
    digitalWrite(playLPin, LOW);
    digitalWrite(playEPin, LOW);
    digitalWrite(recPin, startAddr);

    delay(100);  // Wait for the recording to start

    digitalWrite(recPin, LOW);
}